use std::{time::Instant, sync::Arc};

use tonic::transport::Server;

use crate::{service::{data_container::DataContainer, account::AccountServiceImpl, restaurants::RestaurantServiceImpl, order::OrderServiceImpl, rider::RiderServiceImpl}, gen::mini_mulazim::{account_service_server::AccountServiceServer, restaurant_service_server::RestaurantServiceServer, rider_service_server::RiderServiceServer, order_service_server::OrderServiceServer}};

mod service;
mod gen;

#[tokio::main]
async fn main() {
    let container = Arc::new(DataContainer::new());
    println!("Welcome to use mini-mulazim");
    Server::builder()
        .add_service(AccountServiceServer::new(AccountServiceImpl {data: container.clone()}))
        .add_service(RestaurantServiceServer::new(RestaurantServiceImpl {data: container.clone()}))
        .add_service(RiderServiceServer::new(RiderServiceImpl {data: container.clone()}))
        .add_service(OrderServiceServer::new(OrderServiceImpl {data: container.clone()}))
        .serve("0.0.0.0:7999".parse().expect("Cannot parse tcp address")).await.expect("Cannot start grpc server");
}
